package edu.asu.sefcom.extract.profile;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;


abstract public class MultiFieldParser extends Parser{

	Logger logger = Logger.getLogger(MultiFieldParser.class);

	abstract public List<String> extractFields(String post);
	
	public  List<String> removeheadertrailer(List<String> resultList,
			String header, String trailer) {
		List<String> resultL = new ArrayList<String>();
		logger.debug("remove header trailer called");
		for (String result : resultList) {
			int index = header.length();
			int end = trailer.length();
			int end1 = result.length() - end;
			result = result.substring(index, end1 - 1);
			logger.debug(result + "done");
			resultL.add(result);
		}
		return resultL;
	}

	public void readPosts(String fileData, String start, String end,
			int fromInd, List<String> resultList) {
		boolean return1 = false;
		int beginIndex = 0;
		int endIndex = 0;
		while (beginIndex != -1) {
			beginIndex = fileData.indexOf(start, fromInd);
			endIndex = fileData.indexOf(end, beginIndex);
			int endlength = end.length();
			if (beginIndex != -1) {
				logger.debug("adding**********" + beginIndex + " : " + endIndex);
				String postData = fileData.substring(beginIndex, endIndex
						+ endlength);
				// //pick all the middle parts and place in list
				logger.debug("added" + postData);
				resultList.add(postData);
			}
			fromInd = beginIndex + 1;
		}
		return;
	}

	@Override
	public void parseData(String fileName) {
		
	}

}
